package service.impl;

import entity.Book;
import entity.BookList;
import service.IOperation;

import static entity.BookList.bookNames;

/**
 * 给书架中添加书籍
 */
public class AddBookIOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        // 添加
        System.out.println("您现在进行的是“添加图书”操作(*^▽^*)");
        System.out.println("请输入图书的名称：");
        String bookName = scanner.next();
        if (bookList.contain(bookName)) {
            System.out.println("当前书本已存在!若需编辑图书请选择”更新图书“！");
            return;
        }
        System.out.println("请输入图书作者：");
        String author = scanner.next();
        System.out.println("请输入图书单价：");
        double price = scanner.nextDouble();
        System.out.println("请输入图书类型：");
        String type = scanner.next();
        Book newBook = new Book(bookName, author, price, type);
        bookList.add(newBook);
        bookNames.add(bookName);
        System.out.println("添加成功(*^▽^*)");
    }
}